<html>
	<!--
		@author Jean-Lou Dupont 
	 -->
	<head>
		<style>
		/**
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 */
.code .de1, .code .de2 {font-family: 'Courier New', Courier, monospace; font-weight: normal;}
.code  {background: #EEEEEE; border: padding: 0.2em}
.code .imp {font-weight: bold; color: red;}
.code li, .code li.li1 {font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;}
.code li.li2 {font-weight: bold;}
.code .kw1 {color: #b1b100;}
.code .kw2 {color: #000000; font-weight: bold;}
.code .kw3 {color: #000066;}
.code .co1 {color: #808080; font-style: italic;}
.code .co2 {color: #808080; font-style: italic;}
.code .coMULTI {color: #808080; font-style: italic;}
.code .es0 {color: #000099; font-weight: bold;}
.code .br0 {color: #66cc66;}
.code .sy0 {color: #66cc66;}
.code .st0 {color: #ff0000;}
.code .nu0 {color: #cc66cc;}
.code .me1 {color: #006600;}
.code .me2 {color: #006600;}
.code .re0 {color: #0000ff;}
.code .re1 {color: #ff0000}

		</style>
	</head>
	
	<body>
	
		<div id="content">
		<pre class="code" style="background: #EEEEEE; border: padding: 0.2em"><ol><li class="li1"><div class="de1"><span class="kw2">&lt;?php</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">/**</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* TemplateMethod pattern</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* </span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;* Executes this script and see the result</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* matching the data provided at the bottom.</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* </span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* @author Jean-Lou Dupont</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* @see    http://php-design-patterns-examples.googlecode.com/</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;*/</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">abstract <span class="kw2">class</span> template_method <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="coMULTI">/**</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">	 * Simple state variable</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">	 */</span></div></li><li class="li1"><div class="de1">	<span class="kw2">var</span> <span class="re1">$state</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="coMULTI">/**</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">	 * Constructor</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">	 */</span></div></li><li class="li1"><div class="de1">	<span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">		<span class="re1">$this</span><span class="sy0">-&gt;</span><span class="me1">state</span> <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">	<span class="coMULTI">/**</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">	 * Controller method</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">	 */</span></div></li><li class="li1"><div class="de1">	<span class="kw2">public</span> <span class="kw2">function</span> processEvent<span class="br0">&#40;</span> <span class="re1">$event</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1">		<span class="re1">$this</span><span class="sy0">-&gt;</span><span class="me1">doFirstStep</span><span class="br0">&#40;</span> <span class="re1">$event</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">		<span class="re1">$this</span><span class="sy0">-&gt;</span><span class="me1">doSecondStep</span><span class="br0">&#40;</span> <span class="re1">$event</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="br0">&#125;</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="coMULTI">/**</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">	 * Abstract Method 'doFirstStep'</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">	 */</span></div></li><li class="li1"><div class="de1">	abstract <span class="kw2">public</span> <span class="kw2">function</span> doFirstStep<span class="br0">&#40;</span> <span class="sy0">&amp;</span><span class="re1">$event</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="coMULTI">/**</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">	 * Abstract Method 'doSecondStep'</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">	 */</span></div></li><li class="li1"><div class="de1">	abstract <span class="kw2">public</span> <span class="kw2">function</span> doSecondStep<span class="br0">&#40;</span> <span class="sy0">&amp;</span><span class="re1">$event</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="kw2">class</span> CustomLogic</div></li><li class="li1"><div class="de1">	<span class="kw2">extends</span> template_method <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="kw2">public</span> <span class="kw2">function</span> doFirstStep<span class="br0">&#40;</span> <span class="sy0">&amp;</span><span class="re1">$event</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">		<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="kw2">__METHOD__</span><span class="sy0">.</span><span class="st0">&quot;: state: &quot;</span><span class="sy0">.</span><span class="re1">$this</span><span class="sy0">-&gt;</span><span class="me1">state</span><span class="sy0">.</span><span class="st0">&quot; event: $event<span class="es0">\n</span>&quot;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">		<span class="re1">$this</span><span class="sy0">-&gt;</span><span class="me1">state</span><span class="sy0">++;</span></div></li><li class="li2"><div class="de2">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">	<span class="kw2">public</span> <span class="kw2">function</span> doSecondStep<span class="br0">&#40;</span> <span class="sy0">&amp;</span><span class="re1">$event</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">		<a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="kw2">__METHOD__</span><span class="sy0">.</span><span class="st0">&quot;: state: &quot;</span><span class="sy0">.</span><span class="re1">$this</span><span class="sy0">-&gt;</span><span class="me1">state</span><span class="sy0">.</span><span class="st0">&quot; event: $event<span class="es0">\n</span>&quot;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">		<span class="re1">$this</span><span class="sy0">-&gt;</span><span class="me1">state</span><span class="sy0">++;</span></div></li><li class="li2"><div class="de2">	<span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="coMULTI">/*****************************************************************</span></div></li><li class="li2"><div class="de2"><span class="coMULTI">&nbsp;* 						EXAMPLE                                  *</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*****************************************************************/</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="re1">$cl</span> <span class="sy0">=</span> <span class="kw2">new</span> CustomLogic<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li2"><div class="de2"><span class="re1">$cl</span><span class="sy0">-&gt;</span><span class="me1">processEvent</span><span class="br0">&#40;</span> <span class="st0">'event1'</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="re1">$cl</span><span class="sy0">-&gt;</span><span class="me1">processEvent</span><span class="br0">&#40;</span> <span class="st0">'event2'</span> <span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">__halt_compiler<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li2"><div class="de2"><span class="coMULTI">/*****************************************************************</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;* 						RESULTS                                  *</span></div></li><li class="li1"><div class="de1"><span class="coMULTI">&nbsp;*****************************************************************/</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">CustomLogic<span class="sy0">::</span><span class="me2">doFirstStep</span><span class="sy0">:</span> state<span class="sy0">:</span> <span class="nu0">0</span> event<span class="sy0">:</span> event1</div></li><li class="li2"><div class="de2">CustomLogic<span class="sy0">::</span><span class="me2">doSecondStep</span><span class="sy0">:</span> state<span class="sy0">:</span> <span class="nu0">1</span> event<span class="sy0">:</span> event1</div></li><li class="li1"><div class="de1">CustomLogic<span class="sy0">::</span><span class="me2">doFirstStep</span><span class="sy0">:</span> state<span class="sy0">:</span> <span class="nu0">2</span> event<span class="sy0">:</span> event2</div></li><li class="li1"><div class="de1">CustomLogic<span class="sy0">::</span><span class="me2">doSecondStep</span><span class="sy0">:</span> state<span class="sy0">:</span> <span class="nu0">3</span> event<span class="sy0">:</span> event2</div></li></ol></pre>
		</div>
	</body>

</html>
